from datetime import datetime
from app import db, login_manager
from flask_login import UserMixin

@login_manager.user_loader
def load_user(user_id):
    return User.query.get(int(user_id))

class BilingualContent(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    zh_title = db.Column(db.String(100))
    en_title = db.Column(db.String(100))
    zh_content = db.Column(db.Text)
    en_content = db.Column(db.Text)
    category = db.Column(db.String(50))  # about, contact, service, case
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    images = db.Column(db.String(500))  # 图片路径，多个用逗号分隔

class News(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    zh_title = db.Column(db.String(100))
    en_title = db.Column(db.String(100))
    zh_content = db.Column(db.Text)
    en_content = db.Column(db.Text)
    publish_date = db.Column(db.DateTime, default=datetime.utcnow)
    category = db.Column(db.String(50))  # 资讯分类

class ContactMessage(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(50))
    email = db.Column(db.String(120))
    message = db.Column(db.Text)
    created_at = db.Column(db.DateTime, default=datetime.utcnow)

class User(UserMixin, db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20), unique=True, nullable=False)
    password = db.Column(db.String(60), nullable=False)

class Contact(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    phone = db.Column(db.String(20), nullable=False)
    email = db.Column(db.String(120), nullable=False)
    message = db.Column(db.Text, nullable=False)
    status = db.Column(db.String(20), default='pending')
    created_at = db.Column(db.DateTime, default=datetime.utcnow) 